﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace University.Workshop.Model.CardGame
{
    public enum EnumSuit
    {
        None, Diamond, Heart, Club, Spade
    }

    public enum EnumRank
    {
        None, Ace, Two, Three, Four, Five, Six, Seven, Eight,
        Nine, Ten, Jack, Queen, King
    }


    [Serializable]
    public class Card : IComparable
    {
        private EnumRank Rank;
        private EnumSuit Suit;


        public Card(EnumRank rank, EnumSuit suit)
        {
            this.Rank = rank;
            this.Suit = suit;
        }

        public Card()
            : this(EnumRank.None, EnumSuit.None)
        {
        }

        //IComparable interface method
        public int CompareTo(object obj)
        {
            Card AuxiliarCard = obj as Card;
            if (obj != null)
            {
                if (Rank < AuxiliarCard.RankProperties)
                {
                    return (-1);
                }
                else
                {
                    if (Rank > AuxiliarCard.RankProperties)
                    {
                        return (1);
                    }
                }
                return (0);
            }
            throw new ArgumentException("Object is not a Card");
        }
        public override bool Equals(object obj)
        {
            Card other = obj as Card;
            if (object.ReferenceEquals(other, null))
            {
                return false;
            }
            return this.CompareTo(other) == 0;
        }


        public static bool operator ==(Card left, Card right)
        {
            if (object.ReferenceEquals(left, null))
            {
                return object.ReferenceEquals(right, null);
            }
            return left.Equals(right);
        }
        public static bool operator !=(Card left, Card right)
        {
            return !(left == right);
        }
        public static bool operator <(Card left, Card right)
        {
            return (Compare(left, right) < 0);
        }
        public static bool operator >(Card left, Card right)
        {
            return (Compare(left, right) > 0);
        }
        public static int Compare(Card left, Card right)
        {
            if (object.ReferenceEquals(left, right))
            {
                return 0;
            }
            if (object.ReferenceEquals(left, null))
            {
                return -1;
            }
            return left.CompareTo(right);
        }
        public override int GetHashCode()
        {
            return (this.Rank.GetHashCode() + this.Suit.GetHashCode());
        }


        public override string ToString()
        {
            return (this.Rank + " " + this.Suit);
        }

        public EnumRank RankProperties
        {
            get { return Rank; }
        }

        public EnumSuit SuitProperties
        {
            get { return Suit; }
        }

        public bool IsJacksOrBetter()
        {
            if (Rank == EnumRank.Ace)
            {
                return (true);
            }
            if (Rank >= EnumRank.Jack)
            {
                return (true);
            }
            return (false);
        }
    }
}
